package com.qdsg.ysg.doctor.ui.adapter;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.qdsg.ysg.doctor.R;
import com.qdsg.ysg.doctor.ui.BigImageActivity;
import com.qdsg.ysg.doctor.util.ImageLoaderHelper;
import com.rest.response.RegistrationDetailResponse;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Description
 * Created by lbj on 2023/1/11 13:03
 */

public class PhotoAdapter extends RecyclerView.Adapter<PhotoAdapter.ViewHolder> {


    private AppCompatActivity mContext;
    private List<RegistrationDetailResponse.Photo> mList;

    public PhotoAdapter(Activity context, List<RegistrationDetailResponse.Photo> list) {
        this.mContext = (AppCompatActivity) context;
        this.mList = list;
    }


    @NotNull
    @Override
    public ViewHolder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {
        ViewHolder myHolder;
        myHolder = new ViewHolder( LayoutInflater.from( mContext ).inflate( R.layout.item_photo2, parent, false ) );
        return myHolder;
    }

    @Override
    public void onBindViewHolder(@NotNull ViewHolder holder, final int position) {


        holder.itemView.setOnClickListener( v -> {
            Intent intent = new Intent( mContext, BigImageActivity.class );
            intent.putExtra( "url", mList.get( position ).url );
            intent.putExtra( "type", 1 );
            mContext.startActivity( intent );
        } );
        ImageLoaderHelper.getInstance().GlideImageLoader( mContext, mList.get( position ).thumbnailUrl, holder.image );


    }

    @Override
    public int getItemCount() {
        return mList.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.image)
        ImageView image;
        @BindView(R.id.btn_del_photo)
        ImageView btnDelPhoto;

        public ViewHolder(View itemView) {
            super( itemView );
            ButterKnife.bind( this, itemView );
        }
    }

}
